import { Controller, Get, Post, Body, Request, Query } from '@nestjs/common';
import { ApiOperation, ApiBearerAuth, ApiTags } from '@nestjs/swagger';

import { RoleService } from './role.service';
import { RoleDto, RoleUpdateDto, QueryRoleDto } from './dto/role.dto';
import { JwtNoVerify } from '../../decorators';

@ApiTags('角色模块')
@Controller('role')
export class RoleController {
  constructor(private readonly _roleService: RoleService) {}

  @Get('role-list')
  @JwtNoVerify()
  @ApiOperation({ summary: '获取角色列表' })
  async getRoleList(@Request() req, @Query() query: QueryRoleDto) {
    return this._roleService.getRoleList(req, query);
  }

  @Get('role-info')
  @JwtNoVerify()
  @ApiOperation({ summary: '根据id获取角色信息' })
  async getRoleInfo(@Query('id') id?: string) {
    return this._roleService.getRoleInfo(id);
  }

  @Post('add-role')
  @ApiBearerAuth()
  @ApiOperation({ summary: '新增角色' })
  async addRole(@Request() req, @Body() body: RoleDto) {
    return this._roleService.addRole(req, body);
  }

  @Post('update-role')
  @ApiBearerAuth()
  @ApiOperation({ summary: '新增角色' })
  async updateRole(@Request() req, @Body() body: RoleUpdateDto) {
    return this._roleService.updateRole(req, body);
  }

  @Post('delete-role')
  @ApiBearerAuth()
  @ApiOperation({ summary: '删除角色' })
  async deleteRole(@Request() req, @Body() body: any) {
    return this._roleService.deleteRole(req, body);
  }
}
